package com.fjnldx.mes.mapper.scheduling;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fjnldx.mes.domain.domainReq.DevSnSelectedStatusReq;
import com.fjnldx.mes.domain.domainReq.GongXu;
import com.fjnldx.mes.domain.domainReq.Group;
import com.fjnldx.mes.domain.domainReq.GroupAndOrg;
import com.fjnldx.mes.domain.pojo.Scheduling;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface SchedulingMapper extends BaseMapper<Scheduling> {
    /**
     * 人员管理-集团-级联
     */
    @Select("SELECT DISTINCT `group` FROM scheduling_personnel")
    List<Group> queryPersonnelGroup();

    /**
     * 人员管理-集团-组织
     */
    @Select("SELECT DISTINCT `group`,org FROM scheduling_personnel WHERE `group`=#{group}")
    List<GroupAndOrg> queryPersonnelGroupAndOrg(Group data);

    /*
     * 新增人员排班记录
     */
    @Insert("insert into scheduling(bc,gh,current_work_type,devSn,start_time,end_time) " +
            "values(#{bc},#{gh},#{current_work_type},#{devSn},#{start_time},#{end_time})")
    void addPersonnelClasses(Scheduling data);

    /**
     * 获取机台选择状态
     */
    @Select("SELECT a.*,b.gongxu,b.bc,b.`status`,b.time FROM\n" +
            "(SELECT key_value devSn FROM fzy_dictionary_data_list WHERE dic_bh=(SELECT dic_bh FROM system_mapping_equipment WHERE gongxu=#{gongxu} AND equipment=#{equipment}) ) a\n" +
            "LEFT JOIN\n" +
            "(SELECT * FROM devsn_selected_status WHERE DATEDIFF(time,#{time})=0 AND bc=#{bc}) b\n" +
            "ON \n" +
            "a.devSn=b.devSn")
    List<Map> getDevSnSelectedStatus(DevSnSelectedStatusReq data);

    /**
     * 获取机台设备号
     */
    @Select("SELECT equipment FROM system_mapping_equipment WHERE gongxu=#{gongxu}")
    List<Map<String, Object>> getEquipmentByGx(GongXu data);
}
